package mosquito.g7.blobs;

import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;

public class LineGraph extends Line2D.Double{
	
	private ArrayList<LineGraph> overlapping;
	public LineGraph(){
		super();
		overlapping = new ArrayList<LineGraph>();
		
	}
	
	public LineGraph(double i, double j, double k, double l) {
		super(i, j, k, l);
		overlapping = new ArrayList<LineGraph>();
	}

	public void checkOverlap(LineGraph g){
		if(checkOverlap(this, g)){
			
			overlapping.add(g);
		}
	}
	public static boolean checkOverlap(LineGraph g1, LineGraph g2){
		double m1 = (g1.getY1()-g1.getY2())/(g1.getX1()-g1.getX2());
		double m2 = (g2.getY1()-g2.getY2())/(g2.getX1()-g2.getX2());
		//lines are parallel
		if(m1 == m2)
			return false;
		double b1 = (g1.getY1()-m1*g1.getY1());
		double b2 = (g2.getY1()-m2*g2.getY1());
		
		double x = (b2-b1)/(m1-m2);
		//Determines which x coordinate is higher and then checks if x lies between them
		if(g2.getX1() >= g2.getX2()? g2.getX1() >= x &&  g2.getX2() <= x : g2.getX2() >= x &&  g2.getX1() <= x)
			return true;
		else
			return false;
		
	}

	public ArrayList<LineGraph> getOverlapping() {
		return overlapping;
	}
}
